import path from 'path'
import { readFile } from 'fs/promises';
import terser from '@rollup/plugin-terser';
import { fileURLToPath } from 'url';

const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);

const pkg = JSON.parse(await readFile(
    new URL('../package.json', import.meta.url)
))

const banner =
`/*!
 * WeChat.js v ${pkg.version}
 * (c) 2020-${new Date().getFullYear()} xiawang1024
 */`


const UMD_NAME = 'sdkName' //umd模式全局变量名
const LIB_NAME = 'hndt-demo' //cjs，esm 包名

const builds = [
    {
        banner,
        name:UMD_NAME,
        file:path.join(__dirname,'../dist',`${LIB_NAME}.js`),
        format:'umd',
    },
    {
        banner,
        name:UMD_NAME,
        file:path.join(__dirname,'../dist',`${LIB_NAME}.min.js`),
        format:'umd',
        plugins:[
            terser()
        ]
    },
    {
        banner,
        file:path.join(__dirname,'../dist',`${LIB_NAME}.cjs.js`),
        format:'cjs',
    },
    {
        banner,
        file:path.join(__dirname,'../dist',`${LIB_NAME}.cjs.min.js`),
        format:'cjs',
        plugins:[
            terser()
        ]
    },
    {
        banner,
        file:path.join(__dirname,'../dist',`${LIB_NAME}.esm.js`),
        format:'esm',
    },
    {
        banner,
        file:path.join(__dirname,'../dist',`${LIB_NAME}.esm.min.js`),
        format:'esm',
        plugins:[
            terser()
        ]
    }
]

export default builds